Skip to content

Conversation

@kedevked
Copy link

@kedevked kedevked commented Oct 1, 2025

This PR add the logLevel to the cli following this issue

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

Summary by CodeRabbit

  • New Features
    • Added a global CLI option --log-level (info | warn | error | silent) available for build, dev, inspect, and preview commands.
    • The option configures command output verbosity early in each workflow, letting you reduce or increase console/log noise without changing existing behavior or breaking APIs.

@kedevked kedevked requested a review from colinaaa as a code owner October 1, 2025 12:02
@changeset-bot
Copy link

changeset-bot bot commented Oct 1, 2025

⚠️ No Changeset found

Latest commit: fd7e775

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

📝 Walkthrough

Walkthrough

Added a new optional CLI option --log-level <level> (accepted values: info | warn | error | silent) and applied it to set the global logger level early in several CLI command entrypoints. No other command behavior or control flow was changed.

Changes

Cohort / File(s) Change Summary
CLI option declaration
packages/rspeedy/core/src/cli/commands.ts
Added --log-level <level> to common options and extended CommonOptions with `logLevel?: 'info'
Apply log level in CLI flows
packages/rspeedy/core/src/cli/build.ts, packages/rspeedy/core/src/cli/dev.ts, packages/rspeedy/core/src/cli/inspect.ts, packages/rspeedy/core/src/cli/preview.ts
Each command now conditionally sets logger.level = <provided logLevel> at the start of execution when the corresponding *.logLevel is provided; no other logic or control flow changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitch my whiskers at logs tonight,
Hop through info, warn, and error light,
Quiet burrow when outputs are slight,
A tiny flag in paw sets the sight—
Thump! The logger settles just right. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “feat: add cli log level” clearly and concisely summarizes the primary change of introducing a configurable log level option to the CLI. It focuses on the core feature without extra details and follows a readable format that teammates can quickly understand. The phrasing is specific and directly maps to the changes in the pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cla-assistant
Copy link

cla-assistant bot commented Oct 1, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c85124 and 7a9b78e.

📒 Files selected for processing (1)
  • packages/rspeedy/core/src/cli/commands.ts (1 hunks)

Comment on lines 68 to 71
.option(
'--log-level <level>',
'Set the log level (info | warn | error | silent)',
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify type safety and implementation of logLevel option.

The new --log-level option is added, but several aspects need verification:

  1. Type safety: Ensure BuildOptions includes a logLevel property with the appropriate type (likely a union of 'info' | 'warn' | 'error' | 'silent').
  2. Implementation: Confirm that build.js actually consumes and applies this option.
  3. Validation: Consider adding runtime validation to ensure only valid values are accepted. Commander.js will accept any string by default.
  4. Consistency: Should dev, inspect, and preview commands also support --log-level for consistent logging control across all commands?

Run the following script to verify the implementation:


🏁 Script executed:

#!/bin/bash
# Description: Verify BuildOptions type definition and build.js implementation

# Check BuildOptions type definition
echo "=== Checking BuildOptions type definition ==="
ast-grep --pattern 'export interface BuildOptions {
  $$$
}'

# Check if build.js uses logLevel
echo "=== Checking build.js for logLevel usage ==="
rg -n -C5 'logLevel' packages/rspeedy/core/src/cli/build.js packages/rspeedy/core/src/cli/build.ts

# Check DevOptions, InspectOptions, and PreviewOptions for comparison
echo "=== Checking other Options interfaces ==="
ast-grep --pattern 'export interface DevOptions {
  $$$
}'
ast-grep --pattern 'export interface InspectOptions {
  $$$
}'
ast-grep --pattern 'export interface PreviewOptions {
  $$$
}'

Length of output: 211


The previous script didn’t locate BuildOptions or build.js. Let’s first find the correct build file and interface definitions:


🏁 Script executed:

#!/bin/bash
echo "=== Finding build files ==="
fd -e ts -e js build --strip-cwd-prefix packages/rspeedy/core/src/cli

echo "=== Finding BuildOptions interface ==="
rg -n "export interface BuildOptions" -g "packages/rspeedy/core/src/cli/**/*.ts"

echo "=== Searching for logLevel usage ==="
rg -n "logLevel" -g "packages/rspeedy/core/src/cli/**/*.ts"

Length of output: 279


🏁 Script executed:

#!/bin/bash
echo "=== Finding build files in CLI directory ==="
find packages/rspeedy/core/src/cli -type f | grep -E 'build\.(ts|js)$'

echo "=== Searching for BuildOptions interface in build.ts ==="
rg -n "export interface BuildOptions" packages/rspeedy/core/src/cli/build.ts

echo "=== Printing build.ts head ==="
sed -n '1,200p' packages/rspeedy/core/src/cli/build.ts

echo "=== Searching for logLevel in build.ts ==="
rg -n "logLevel" packages/rspeedy/core/src/cli/build.ts

echo "=== Searching for logLevel in commands.ts ==="
rg -n "logLevel" packages/rspeedy/core/src/cli/commands.ts

Length of output: 2454


🏁 Script executed:

#!/bin/bash
# Locate commands.ts
echo "=== commands.ts path ==="
find packages/rspeedy/core/src/cli -type f | grep 'commands\\.ts$'

# Print first 200 lines of commands.ts
echo "=== commands.ts head ==="
sed -n '1,200p' packages/rspeedy/core/src/cli/commands.ts

# Extract CommonOptions interface
echo "=== CommonOptions interface ==="
rg -n "export interface CommonOptions" -C5 packages/rspeedy/core/src/cli/commands.ts

Length of output: 4108


Add and implement the log-level option across all commands.

  • Extend CommonOptions in packages/rspeedy/core/src/cli/commands.ts to include
    logLevel?: 'info' | 'warn' | 'error' | 'silent' so it’s available on BuildOptions, DevOptions, InspectOptions, and PreviewOptions.
  • In packages/rspeedy/core/src/cli/build.ts, configure the logger with the provided level (e.g. logger.setLevel(buildOptions.logLevel)) before running the build.
  • Enforce valid values at parse time—use Commander’s choice support or add a manual check to reject anything outside info|warn|error|silent.
  • Mirror the --log-level option and its handling in the dev, inspect, and preview commands for consistent logging control.
🤖 Prompt for AI Agents
packages/rspeedy/core/src/cli/commands.ts around lines 68-71: the CLI currently
defines a --log-level option but CommonOptions type lacks logLevel and other
command handlers don't consume it; update CommonOptions to include logLevel?:
'info' | 'warn' | 'error' | 'silent' so BuildOptions, DevOptions,
InspectOptions, and PreviewOptions inherit it; in build/dev/inspect/preview
command entrypoints (e.g. packages/rspeedy/core/src/cli/build.ts and analogous
files) read the parsed option and call the logger configuration before running
the command (e.g. logger.setLevel(buildOptions.logLevel)); enforce allowed
values at parse time by adding Commander choices for the option or by adding an
early validation that rejects values not in ['info','warn','error','silent'];
add the same --log-level option/choices and handling to the dev, inspect, and
preview command definitions to ensure consistent behavior.

Copy link
Collaborator

@colinaaa colinaaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR. Just like @coderabbitai said in #1864 (comment), we need to implement the logLevel option alone the the CLI flag.

@kedevked kedevked force-pushed the feature/add-cli-log-level branch from 6f43730 to fd7e775 Compare October 3, 2025 13:42
@kedevked
Copy link
Author

kedevked commented Oct 3, 2025

@colinaaa , the logLevel is now implemented accross dev, inspect, and preview commands

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f43730 and fd7e775.

📒 Files selected for processing (5)
  • packages/rspeedy/core/src/cli/build.ts (1 hunks)
  • packages/rspeedy/core/src/cli/commands.ts (2 hunks)
  • packages/rspeedy/core/src/cli/dev.ts (1 hunks)
  • packages/rspeedy/core/src/cli/inspect.ts (1 hunks)
  • packages/rspeedy/core/src/cli/preview.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/rspeedy/core/src/cli/dev.ts
  • packages/rspeedy/core/src/cli/preview.ts
  • packages/rspeedy/core/src/cli/build.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/rspeedy/core/src/cli/inspect.ts (1)
packages/rspeedy/core/src/index.ts (1)
  • logger (29-29)
🔇 Additional comments (2)
packages/rspeedy/core/src/cli/commands.ts (1)

22-22: LGTM! Type definition is correct.

The logLevel property is properly typed with a union of valid log levels and will be inherited by all command option interfaces (BuildOptions, DevOptions, InspectOptions, PreviewOptions).

packages/rspeedy/core/src/cli/inspect.ts (1)

23-25: LGTM! Logger configuration is correctly implemented.

The log level is set early in the flow, before any initialization logic, which ensures consistent logging behavior throughout the command execution. The conditional check prevents setting the level when no value is provided.

Note: Input validation should be added at the CLI option parsing level (see comment on commands.ts), so invalid values never reach this point.

Comment on lines +47 to +50
.option(
'--log-level <level>',
'Set the log level (info | warn | error | silent)',
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Add validation for log level values.

Commander.js will accept any string for --log-level, but only 'info' | 'warn' | 'error' | 'silent' are valid. Without validation, invalid values will be silently passed through, potentially causing runtime errors.

Apply this diff to add validation using Commander's .choices():

     .option(
       '--log-level <level>',
       'Set the log level (info | warn | error | silent)',
     )
+    .addOption(
+      new Option('--log-level <level>', 'Set the log level')
+        .choices(['info', 'warn', 'error', 'silent'])
+    )

Note: You'll need to import Option from commander:

 import type { Command } from 'commander'
+import { Option } from 'commander'

Run the following script to verify that all command implementations (build, dev, preview) consume the logLevel option consistently:


🏁 Script executed:

#!/bin/bash
# Description: Verify that all CLI commands implement logLevel option handling

echo "=== Checking build.ts for logLevel usage ==="
rg -n -C3 'buildOptions\.logLevel|logger\.level' packages/rspeedy/core/src/cli/build.ts

echo "=== Checking dev.ts for logLevel usage ==="
rg -n -C3 'devOptions\.logLevel|logger\.level' packages/rspeedy/core/src/cli/dev.ts

echo "=== Checking preview.ts for logLevel usage ==="
rg -n -C3 'previewOptions\.logLevel|logger\.level' packages/rspeedy/core/src/cli/preview.ts

echo "=== Checking inspect.ts for logLevel usage (for comparison) ==="
rg -n -C3 'inspectOptions\.logLevel|logger\.level' packages/rspeedy/core/src/cli/inspect.ts

Length of output: 1035


Add validation for --log-level via Commander.js .choices()
Restrict allowed values to info | warn | error | silent by replacing the loose .option() call. For example:

 import type { Command } from 'commander'
+import { Option } from 'commander'

   command
-    .option(
-      '--log-level <level>',
-      'Set the log level (info | warn | error | silent)',
-    )
+    .addOption(
+      new Option('--log-level <level>', 'Set the log level')
+        .choices(['info', 'warn', 'error', 'silent']),
+    )

All commands (build, dev, preview, inspect) already read logLevel and set logger.level.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.option(
'--log-level <level>',
'Set the log level (info | warn | error | silent)',
)
import type { Command } from 'commander'
import { Option } from 'commander'
command
.addOption(
new Option('--log-level <level>', 'Set the log level')
.choices(['info', 'warn', 'error', 'silent']),
)
🤖 Prompt for AI Agents
In packages/rspeedy/core/src/cli/commands.ts around lines 47 to 50, the
--log-level option is currently defined without validation; change the Commander
option to restrict allowed values to the set ['info','warn','error','silent']
using Commander.js .choices() (and optionally provide a sensible default like
'info'), so parsing will fail on invalid inputs and downstream code that reads
logLevel/logger.level always receives one of the allowed values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants